 <?php
	print("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?> \n");
	print("<PID>\n");
	if(!isset($_GET["PID"]))
	{
		print("</PID>\n");
		return;
	}
	$db = mysql_connect("localhost","root","root");
    mysql_select_db("brainway");
    
    //delete DKRelation
    $query = "delete from datasource_knowledge 
        where datasource_knowledge.KID in (select knowledge_name.KID from knowledge_name where project_id=".$_GET["PID"].")";
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>0</error>");
        print("</PID>\n");
		return;
    }
    
    //delete KConRelation
    $query = "delete from knowledge_conclusion 
        where KID in (select KID from knowledge_name where project_id=".$_GET["PID"].")";
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>1</error>");
        print("</PID>\n");
		return;
    }
    
    //delete conclusion
    $query = "delete from conclusion_discription 
            where ConID in (select ConID from conclusion_name where project_id=".$_GET["PID"].")";
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>2</error>");
        print("</PID>\n");
		return;
    }
    
    $query = "delete from conclusion_name where project_id=".$_GET["PID"];
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>3</error>");
        print("</PID>\n");
		return;
    }
    
     //delete knowledge
    $query = "delete from knowledge_discription 
            where KID in (select KID from knowledge_name where project_id=".$_GET["PID"].")";
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>4</error>");
        print("</PID>\n");
		return;
    }
    
    $query = "delete from knowledge_name where project_id=".$_GET["PID"];
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>5</error>");
        print("</PID>\n");
		return;
    }
    
    //case
	$query = "delete from case_discription where CID in (select CID from case_name where project_id=".$_GET["PID"].")";
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>6</error>");
        print("</PID>\n");
		return;
    }
    
    $query = "delete from datasource_discription
                where DID in
                (   select datasource_name.DID from datasource_name where CID in (select CID from case_name where project_id=".$_GET["PID"].")
                )";
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>7</error>");
        print("</PID>\n");
		return;
    }
    
    $query = "delete from datasource_name
                where CID in (select CID from case_name where project_id=".$_GET["PID"].")";
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>8</error>");
        print("</PID>\n");
		return;
    }
    $query = "delete from case_name where project_id=".$_GET["PID"];
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>9</error>");
        print("</PID>\n");
		return;
    }
    $query = "delete from project_discription where PID=".$_GET["PID"];
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>10</error>");
        print("</PID>\n");
		return;
    }
    $query = "delete from project_name where PID=".$_GET["PID"];
    $result = mysql_query($query);
    if($result==null)       //name has existed
    {
        print("<error>11</error>");
        print("</PID>\n");
		return;
    }
    
    print($_GET["PID"]."</PID> \n");
?>